package com.bobochang.warehouse.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Objects;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 合同与施工类型关系表
 * @TableName construction_and_contract
 */
@TableName(value ="construction_and_contract")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ConstructionAndContract implements Serializable {
    /**
     * 
     */
    @TableId(type = IdType.AUTO)
    private Integer id;

    /**
     * 合同id
     */
    private Integer contractId;

    /**
     * 施工类型id
     */
    private Integer construction;

    /**
     * 单位
     */
    private Integer unitId;
    /**
     * 单价
     */
    private BigDecimal unitPrice;
    /**
     * 数量
     */
    private BigDecimal number;
    /**
     * 金额
     */
    private BigDecimal money;

    public ConstructionAndContract(Integer contractId, Integer construction) {
        this.contractId = contractId;
        this.construction = construction;
    }

    public ConstructionAndContract(Integer contractId, Integer construction, BigDecimal number, BigDecimal unitPrice, Integer unitId) {
        this.contractId = contractId;
        this.construction = construction;
        this.number = number;
        this.unitPrice = unitPrice;
        this.unitId = unitId;
        this.money = number.multiply(unitPrice).setScale(4, RoundingMode.HALF_UP);
    }

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ConstructionAndContract itemKey = (ConstructionAndContract) o;
        return contractId.equals(itemKey.contractId) &&
                construction.equals(itemKey.construction);
    }

    @Override
    public int hashCode() {
        return Objects.hash(contractId, construction);
    }

    public static int getHashCode(Integer contractId, Integer construction){
        return Objects.hash(contractId, construction);
    }
}